#!usr/bin/env python  
# -*- coding:utf-8 _*-
'''
@author:robot
@file: clone_source_node.py 
@version:
@time: 2022/01/06 
'''
from TapClientCore.T04_logic.Dag01.node.node_base import NodeBase, TapdataNoThisDataSource


class CommonCloneSourceNode(NodeBase):
    """
    CloneSourceNode
    """

    def __init__(self, name, table: []):
        self.id = self.newId
        if isinstance(name, dict):
            self.name = name['name']
        else:
            self.name = name
        self.table = table
        self.attribute = self.sole()

    def sole(self):
        response = self.TM.get_connections_by_name(self.name)
        if not response['data']:
            raise TapdataNoThisDataSource
        this_node = {
            'id': self.id,
            'name': self.name,
            'inputLanes': [],
            'outputLanes': [],
            'connectionId': response['data'][0]['id'],
            'database_type': response['data'][0]['database_type']
        }
        return this_node


if __name__ == '__main__':
    t = CommonCloneSourceNode('auto_mysql', ['my2'])
    print(t.attr)
